package com.kantboot.business.bp.domain.entity;

import com.kantboot.util.core.jpa.KantbootGenerationType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 问题的实体类
 */
@Entity
@Getter
@Setter
@Table(name = "bus_bp_problem")
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@DynamicInsert
@NoArgsConstructor
public class BusBpProblem implements Serializable {

    /**
     * 主键
     */
    @Id
    @GenericGenerator(name = "snowflakeId",strategy = KantbootGenerationType.SNOWFLAKE)
    @GeneratedValue(generator = "snowflakeId")
    @Column(name = "id")
    private Long id;

    /**
     * 文字
     */
    @Column(name = "t_text", length = 1000)
    private String text;

    /**
     * 图片列表字符串
     */
    @Column(name = "image_list_str", length = 1000)
    private String imageListStr;

    /**
     * 问题的用户id
     */
    @Column(name = "user_id")
    private Long userId;

    /**
     * 年级id
     */
    @Column(name = "grade_id")
    private Long gradeId;

    /**
     * 学科id
     */
    @Column(name = "subject_id")
    private Long subjectId;

    @OneToOne
    @JoinColumn(name = "grade_id", insertable = false, updatable = false)
    private BusBpGrade grade;

    @OneToOne
    @JoinColumn(name = "subject_id", insertable = false, updatable = false)
    private BusBpSubject subject;

    @OneToMany
    @JoinColumn(name = "problem_id")
    private List<BusBpProblemAnswer> answers;

    /**
     * 收藏数
     */
    @Column(name = "collection_count")
    private Long collectionCount;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "gmt_create")
    private Date gmtCreate;

    /**
     * 最后一次修改时间
     */
    @LastModifiedDate
    @Column(name = "gmt_modified")
    private Date gmtModified;

    /**
     * 自己有没有收藏
     */
    @Transient
    private Boolean isCollectedSelf;



}
